Javascript replace space with regex


\s : means "one space"

\s+ : means "one or more spaces"

let stringWithSpace = '  A B  C   D EF ';

console.log(str.replace(/\s/g, '#'));                                
// ##A#B##C###D#EF# => means one space replace by one #;

console.log(str.replace(/\s+/g, '#'));                             
// #A#B#C#D#EF#  => means one or more spaces, all replace by #;
#javascript #replace #RegEx






你可能感興趣的文章

【JS幼幼班】Step.07 基本語法:物件型別(object、function)

【JS幼幼班】Step.07 基本語法:物件型別(object、function)

Day 128

Day 128

[極短篇] SQL injection

[極短篇] SQL injection






留言討論